package edu.zhangxu.dao;

import edu.zhangxu.pojo.Solution;

import java.math.BigInteger;
import java.sql.Connection;

public class SolutionDaoImp extends BaseDao implements SolutionDao {

    @Override
    public void insert(Connection con, Solution solution) {
        String sql = "INSERT INTO solutions(problem_id, judger, language, code) VALUES (?, ?, ?, ?)";
        update(con, sql, solution.getProblemId(), solution.getJudger(), solution.getLanguage(), solution.getCode());
    }

    @Override
    public int getId(Connection con) {
        String sql = "SELECT LAST_INSERT_ID()";
        return ((BigInteger) getValue(con, sql)).intValue();
    }

    @Override
    public Solution getSimpleSolutionById(Connection con, int id) {
        String sql = "SELECT id, problem_id problemId, language, result, time, memory," +
                "error_info errorInfo, wrong_data wrongData, judge_time judgeTime FROM solutions WHERE id=?";
        return getInstance(con, Solution.class, sql, id);
    }
}
